package com.example.demo.model;

import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.util.List;

/**
 * TODO
 *
 * @author wuhong-016
 * @version v1.0.0
 * @time: 2021/6/3 21:36
 */
public class HttpResult {

    public final static int SUCCESS_CODE = 0;
    public final static String SUCCESS_MSG = "success";

    private int code;
    private String msg;
    private Object data;

    public static HttpResult success() {
        return new HttpResult(SUCCESS_CODE, SUCCESS_MSG);
    }

    public static HttpResult success(Object data) {
        return new HttpResult(SUCCESS_CODE, SUCCESS_MSG).setData(data);
    }

    public static HttpResult error(int code, String msg) {
        return new HttpResult(code, msg);
    }

    private HttpResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public HttpResult setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public HttpResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Object getData() {
        return data;
    }

    public HttpResult setData(Object data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
